package com.tz.fruit.entity;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* 订单明细实体类
*/
@Entity
@Table(name="FRUIT_ORDERITEM")
public class OrderItem implements Serializable{
	private Long itemId;//订单明细ID
	
	private String pNo;//商品编号

	private String imgUrl;//商品图片
	private String pName;//商品名称
	private String standard;//商品规格
	private double price;//商品单价
	private int count;//购买数量
	private double total;//此明细的总价格
	private int commented;//0：未评论  1：已评论
	
	private Order order;//此明细所属的订单
	private Cart cart;//所属的购物车
	
	public OrderItem() {
		// TODO Auto-generated constructor stub
	}

	public OrderItem(String proNo, String imgUrl, String pName, String standard, double price, int count,
			double total,int commented, Order order) {
		super();
		this.pNo = proNo;
		this.imgUrl = imgUrl;
		this.pName = pName;
		this.standard = standard;
		this.price = price;
		this.count = count;
		this.total = total;
		this.commented = commented;
		this.order = order;
	}
	
	public OrderItem(String proNo, String imgUrl, String pName, String standard, double price, int count,
			double total, int commented,Cart cart) {
		super();
		this.pNo = proNo;
		this.imgUrl = imgUrl;
		this.pName = pName;
		this.standard = standard;
		this.price = price;
		this.count = count;
		this.total = total;
		this.commented = commented;
		this.cart = cart;
	}

	@Id
	@GeneratedValue
	public Long getItemId() {
		return itemId;
	}

	public void setItemId(Long itemId) {
		this.itemId = itemId;
	}
	
	public String getpNo() {
		return pNo;
	}

	public void setpNo(String pNo) {
		this.pNo = pNo;
	}

	public String getImgUrl() {
		return imgUrl;
	}

	public void setImgUrl(String imgUrl) {
		this.imgUrl = imgUrl;
	}

	public String getpName() {
		return pName;
	}

	public void setpName(String pName) {
		this.pName = pName;
	}

	public String getStandard() {
		return standard;
	}

	public void setStandard(String standard) {
		this.standard = standard;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public double getTotal() {
		return total;
	}

	public void setTotal(double total) {
		this.total = total;
	}
	
	public int getCommented() {
		return commented;
	}

	public void setCommented(int commented) {
		this.commented = commented;
	}

	@ManyToOne
	@JoinColumn(name="orderId")
	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}
	
	@ManyToOne
	@JoinColumn(name="cartId")
	public Cart getCart() {
		return cart;
	}

	public void setCart(Cart cart) {
		this.cart = cart;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((itemId == null) ? 0 : itemId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OrderItem other = (OrderItem) obj;
		if (itemId == null) {
			if (other.itemId != null)
				return false;
		} else if (!itemId.equals(other.itemId))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "OrderItem [itemId=" + itemId + ", pNo=" + pNo + ", imgUrl=" + imgUrl + ", pName=" + pName
				+ ", standard=" + standard + ", price=" + price + ", count=" + count + ", total=" + total + "]";
	}

}
